<?php
// +----------------------------------------------------------------------
// | 小说系统 [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------

namespace app\admin\controller;
use app\common\controller\Admin;

class Upload extends Admin {

	public function _empty() {
		$controller = controller('common/Upload');
		$action     = ACTION_NAME;
		return $controller->$action();
	}

	public function Uploadtxt() {
		$config = config('attachment_upload');
		// 获取表单上传文件
		$file = request()->file('file');
		$info = $file->move($config['rootPath']);
		
		if ($info) {
			$return['status'] = 1;
			$return['info']   = array(
				"id"=>time(),
				"path"=>$config['rootPath']."/".$info->getSaveName(),
				"url"=>$config['rootPath']."/".$info->getSaveName(),
				"name"=>$_FILES['file']['name']
			);
		} else {
			$return['status'] = 0;
			$return['info']   = $file->getError();
		}
		echo json_encode($return);
		/*
		if ($info) {
			echo $config['rootPath']."/".$info->getSaveName();
		} else {
			echo $file->getError();
		}*/
		exit();
	}

	public function Uploadzip() {
		$config = config('attachment_upload');
		
		// 获取表单上传文件
		$file = request()->file('ebook');
		$info = $file->move(str_replace("attachment","zip",$config['rootPath']));
		
		if ($info) {
			echo str_replace("attachment","zip",$config['rootPath'])."/".$info->getSaveName();
		} else {
			echo $file->getError();
		}
		exit();
	}
	/*******上传验证文件*********/
	public function Uploadtext() {
		$config = "./";
		// 获取表单上传文件
		if (file_exists(ROOT_PATH.$_FILES["ebook"]["name"]))
		{
			echo ROOT_PATH.$_FILES["ebook"]["name"];
		}else{
			move_uploaded_file($_FILES["ebook"]["tmp_name"],ROOT_PATH.$_FILES["ebook"]["name"]);
			echo ROOT_PATH.$_FILES["ebook"]["name"];
		}
		exit();
	}

    /**
     * Notes: 上传图片
     * @author: Zhu
     * @since: 2023/1/12 15:52
     */
    public function UploadPicture() {
        $config = config('picture_upload');
        // 获取表单上传文件
        $file = request()->file('file');
        $info = $file->move($config['rootPath']);

        if ($info) {
            $return['status'] = 1;
            $return['info']   = array(
                "id"=>time(),
                "path"=>$config['rootPath']."/".$info->getSaveName(),
                "url"=>$config['rootPath']."/".$info->getSaveName(),
                "name"=>$_FILES['file']['name']
            );
        } else {
            $return['status'] = 0;
            $return['info']   = $file->getError();
        }
        echo json_encode($return);
        exit();
    }
}